<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zuipin.mapper.${className!""}Mapper">  

  <resultMap type="${className!""}" id="${obName!""}Map">
  		<id column="id" property="id"/>
  	<#list propertyEntityList as pro>
  		<#if pro.pkType=0>
  			<result column="${pro.columnName}"  property="${pro.propName}" />
  		</#if>
  	</#list>
  </resultMap>
  
  <!--查找${remark!""}  -->
  <select id="findById" resultMap="${obName!""}Map">
    select * from ${talbleName!""} where <#assign i=0 /><#list propertyEntityList as pro><#if pro.pkType=1><#if (i>0) >,</#if>${pro.columnName} = ${r"#"}{${pro.propName}}<#assign i=i+1 /></#if></#list>
  </select>  
  
  <!-- 插入${remark!""} -->
  <insert id="insert" parameterType="com.zuipin.entity.${className!""}" > 
	  <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
		SELECT LAST_INSERT_ID() AS id
		</selectKey>
        insert into  ${talbleName!""}(<#list propertyEntityList as pro><#if pro.pkType=0>${pro.columnName}<#if pro_has_next>,</#if></#if></#list>)
        values (<#list propertyEntityList as pro><#if pro.pkType=0>${r"#"}{${pro.propName}}<#if pro_has_next>,</#if></#if></#list>)
  </insert>
  
   <!--更新${remark!""}  -->
  <update id="update" parameterType="com.zuipin.entity.${className!""}">
  	update ${talbleName!""} 
  	<set>
  	<#list propertyEntityList as pro>
  	<#if pro.pkType=0><if test="${pro.propName}!=null <#if pro.propType ='String'>and ${pro.propName}!='' </#if>">${pro.columnName}=${r"#"}{${pro.propName}},</if></#if><#if !pro_has_next>,</#if>
  	</#list>
  	</set>
  	 where id=${r"#"}{id}
  </update>
  
  <!-- 删除${remark!""}  -->
  <delete id="delete" >
  	delete from ${talbleName!""} where <#list propertyEntityList as pro><#if pro.pkType=1>${pro.columnName} = ${r"#"}{${pro.propName}}</#if><#if !pro_has_next></#if></#list>
  </delete>
 
   <!--搜索${remark!""}  -->
   <select id="seach${className!""}" resultMap="${obName!""}Map">
     select * from ${talbleName!""} pro where 1=1
     <#list propertyEntityList as pro>	  	
  	  	<#if pro.pkType=0>
  	  	<if test="${obName!""}.${pro.propName}!=null <#if pro.propType ='String'>and ${obName!""}.${pro.propName}!='' </#if>"> 
  	  	and <#if pro.propType ='String'>${pro.columnName} like concat(concat('%',${r"#"}{${obName!""}.${pro.propName}}),'%')<#else>${pro.columnName}=${r"#"}{${obName!""}.${pro.propName}}</#if> 
  	  	</if>  	
  	 	</#if>
  	</#list>
   </select> 
  
  
  
</mapper>